using UnityEngine;
using System.Collections;

public class Shoot : MonoBehaviour {

    int id = 0;
	int pontos = 0;
	void Start ()
    {
        this.gameObject.AddComponent("MeshRenderer");
        this.gameObject.AddComponent("MeshFilter");
        this.gameObject.AddComponent("BoxCollider");
        this.gameObject.AddComponent("Rigidbody");

        this.gameObject.GetComponent<Rigidbody>().useGravity = false;
		this.gameObject.rigidbody.constraints = RigidbodyConstraints.FreezeAll;

        this.gameObject.GetComponent<BoxCollider>().size = new Vector3(0.5f, 0.5f, 0.5f);

       

 

        transform.localPosition = new Vector3(-5f, -2.4f, -1f);


        Mesh mesh = Quad.Create(0.7f, 0.3f);

        this.gameObject.GetComponent<MeshFilter>().mesh = mesh;
        this.gameObject.GetComponent<MeshRenderer>().material = AtlasManager.globalMaterial;

        this.gameObject.GetComponent<MeshFilter>().mesh.uv = new Vector2[]
		{
			new Vector2(AtlasManager.rects[id].xMin, AtlasManager.rects[id].yMax),
			new Vector2(AtlasManager.rects[id].xMax, AtlasManager.rects[id].yMax),
			new Vector2(AtlasManager.rects[id].xMax, AtlasManager.rects[id].yMin),
			new Vector2(AtlasManager.rects[id].xMin, AtlasManager.rects[id].yMin)
		};
	}
	

	
	void Update () 
    {
        this.gameObject.transform.Translate(0.2f,0,0);
	}

    void OnCollisionEnter(Collision c)
    {
        if (c.gameObject.tag == "Colisor")
        {
            Destroy(this.gameObject);
			Destroy (c.gameObject);
			
			pontos ++;
			
			Debug.Log("Pontos =" + pontos);
			
			
			
		}
		
		if(pontos == 10)
		Application.LoadLevel("Inicio");	
		
    }
}
